﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Refract.Navigation;
using Refract.Views;

namespace Refract.Tests
{
    
    [TestClass]
    public class PageItemFixture
    {
        PageItem _pageItem = null;

        [TestMethod]
        public void PageItem_is_constructed_correctly()
        {

            Assert.IsNotNull(_pageItem);
            Assert.AreEqual(typeof(TestViewModel), _pageItem.ViewModelType);
            Assert.IsNotNull(_pageItem.Command);
            Assert.IsTrue(_pageItem.Command.CanExecute(null));

        }

        [TestMethod]
        public void PageItem_command_raises_navigated_event()
        {

            bool eventRaised = false;
            string dataReturned = string.Empty;

            _pageItem.OnNavigate += new EventHandler<EventArgs<string>>((s, e) => { eventRaised = true; dataReturned = e.Data; });
            const string Data = "Data";
            _pageItem.Command.Execute(Data);

            Assert.IsTrue(eventRaised);
            Assert.AreEqual(Data, dataReturned);
        }

        [TestInitialize]
        public void SetupTest()
        {
            _pageItem = new PageItem("PageItem", typeof(TestViewModel));

        }
    }
}